//1. 安装
//2. 导入
const mongoose = require("mongoose");

//3. 连接 mongodb 数据库
mongoose.connect("mongodb://127.0.0.1:27017/h5220707");

//4. 设置回调  on  when 当...时候
mongoose.connection.on("open", () => {
  //5. 声明文档结构对象 
  const MovieSchema = new mongoose.Schema({
    name: String,
    actors: Array,
    releaseYear: Number,
  });

  //6. 创建文档模型对象
  const MovieModel = mongoose.model("movie", MovieSchema);

  //7. 文档操作
  MovieModel.insertMany(
    [
      {
        name: "夏洛特烦恼",
        actors: ["沈腾", "马丽", "尹正"],
        releaseYear: 2015,
      },
      {
        name: "西红柿首富",
        actors: ["沈腾", "常远", "魏翔"],
        releaseYear: 2016,
      },
    ],
    (err, data) => {
      if(err) throw err;
      console.log(data);
      mongoose.connection.close();
    }
  );
});

/**
 * 1. 注册
 * 2. 编写文章
 * 3. 上架商品
 * 4. 评价
 * 5. 广告
 * 6. 上架视频
 */